package com.novasoftware.novagooglemap.adapter;

import java.util.List;

import com.novasoftware.novagooglemap.R;
import com.novasoftware.novagooglemap.db.entity.Agent;
import com.novasoftware.novagooglemap.framework.fragment.RemoteImageView;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class LoginAdpter extends ArrayAdapter<Agent> {

	List<Agent> _dsAgents;
	Activity _activity;
	
	public LoginAdpter(Activity context, int textViewResourceId,
			List<Agent> objects) {
		super(context, textViewResourceId, objects);
		_dsAgents = objects;
		_activity = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		if(row==null)
		{
			LayoutInflater inflater = _activity.getLayoutInflater();
			row = inflater.inflate(R.layout.login_item, null);
			Holder holder = new Holder();
			holder.imageView = (RemoteImageView)row.findViewById(R.id.txtImage);
			holder.imageView.setDefaultImage(R.drawable.male);
			holder.textView = (TextView)row.findViewById(R.id.txtView);
			row.setTag(holder);
		}
		Holder holder2 = (Holder) row.getTag();
		Agent agent = _dsAgents.get(position);
		holder2.imageView.setImageUrl(agent.Image);
		holder2.textView.setText(agent.Name);
		return row;
	}

	class Holder
	{
		RemoteImageView imageView;
		TextView textView;
	}
}
